{% extends "layout.html" %}
{% block content %}
    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form" lay-filter="dataItem">
			<table class="layui-table">
				<tbody>
                    <tr>
						<th><span class="x-red">*</span>线圈值</th>
						<td colspan="1">
                            <input type="text" id="data1" name="data1" required="required" lay-verify="required"
                            autocomplete="off" class="layui-input">
                        </td>
						<th><span class="x-red">*</span>离散量</th>
						<td colspan="1">
                            <input type="text" id="data2" name="data2" required="required" lay-verify="required"
                            autocomplete="off" class="layui-input">
                        </td>
                    </tr>
                    <tr>
						<th><span class="x-red">*</span>输入寄存器</th>
						<td colspan="1">
                            <input type="text" id="data3" name="data3" required="required" lay-verify="required"
                            autocomplete="off" class="layui-input">
                        </td>
						<th><span class="x-red">*</span>保持寄存器</th>
						<td colspan="1">
                            <input type="text" id="data4" name="data4" required="required" lay-verify="required"
                            autocomplete="off" class="layui-input">
                        </td>
                    </tr>
					<tr>
						<td colspan="2" style="text-align: center;">
                            <button id="confirmBtn" class="layui-btn" lay-filter="save" lay-submit="">
                                保存
                            </button>
                        </td>
						<td colspan="2" style="text-align: center;">
							<button  type="reset" class="layui-btn">
                                重置
                            </button>
						</td>
					</tr>
                </tbody>
            </table>
        </form>
    </div>
    <script>
        var data_index=GetQueryString('data_index');
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form
            ,layer = layui.layer;

            //监听提交
            form.on('submit(save)', function(data){
                data.field['data_index']=data_index;
                $.ajax({url:'saveDefaultDataItemValue',type:'POST',dataType:'json',data:data.field,success:function(data){
                    if(data.code==0){
                        // layer.msg('操作成功!');
                        layer.alert("操作成功", {icon: 6},function () {
                            parent.location.reload();
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                }});
                return false;
            });
            layer.ready(function(){
                data={'data_index':data_index};
                $('#confirmBtn').html('保存');
                $.ajax(
                {
                    url:'readDefaultDataItem'
                    ,type:'POST'
                    ,dataType:'json'
                    ,data:data
                    ,success:function(data){
                        //设置内容
                        if(data.code==0){
                            dataItem=data.data[0];
                            form.val("dataItem",{
                                data1:dataItem.value1,
                                data2:dataItem.value2,
                                data3:dataItem.value3,
                                data4:dataItem.value4,
                            });
                            layui.form.render();
                        }
                    }
                });
            });
        });
    </script>
{% endblock %}